import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void initArrayOrder(int[] array){
        for (int i = 0; i < array.length ; i++) {
            array[i] =i;
           // array[i] = array.length-i;
        }
    }
    public static void initArrayNotOrder(int[] array){
        Random random = new Random();//随机生成数
        for (int i = 0; i < array.length ; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testInsertSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时："+(endTime-startTime));
    }
    public static void testShellSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(endTime-startTime));
    }
    public static void testSelectSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时："+(endTime-startTime));
    }
    public static void testHeapSortSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时："+(endTime-startTime));
    }
    public static void testQuickSortSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速序耗时："+(endTime-startTime));
    }

    public static void main1(String[] args) {
        int[] array = new int[10_0000];
        initArrayOrder(array);// 耗时：5  逆序耗时：1935
        //initArrayNotOrder(array);//耗时：1099

//        testInsertSort(array);
//
//        testShellSort(array);
//
//        testSelectSort(array);
//
//        testHeapSortSort(array);

        testQuickSortSort(array);


    }
    public static void main(String[] args) {
        int[] array = {1,21,3,14,51,6,17};
        Sort.mergeSort2(array);
        System.out.println(Arrays.toString(array));
    }

}

